package ac.github.os.internal.hook

import ac.github.os.OriginSkill
import ac.github.os.api.central.SkillCentral
import ac.github.os.internal.core.trigger.PlayerTrigger
import org.bukkit.entity.Player
import taboolib.common.platform.Awake
import taboolib.platform.compat.PlaceholderExpansion

@Awake
object PlaceholderHook : PlaceholderExpansion {

    override val identifier: String
        get() = "os"

    override fun onPlaceholderRequest(player: Player, args: String): String {
        val playerTrigger = PlayerTrigger(player)
        val skillScheme = OriginSkill.schemes.firstOrNull { it.key == args }
        return if (skillScheme != null) {
            String.format("%.1f",(SkillCentral.surplus(playerTrigger, skillScheme) / 1000).coerceAtLeast(0.0))
        } else "0.0"
    }
}